package com.czbank.financing.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.czbank.financing.Entity.Recommend;
import com.czbank.financing.Entity.UserProductRecommend;
import com.czbank.financing.Entity.UserSet;
import com.czbank.financing.service.UserProductRecommendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: thinkpad
 * @Date: 2019/7/17 13:40
 * @Description:
 */
@CrossOrigin
@RestController
public class RecommendController {

    @Autowired
    private UserProductRecommendService userProductRecommendService;

    @RequestMapping("/Recommend")
    public Object TotalProduct(@RequestBody JSONObject jsonObject){
        UserSet userSet = new UserSet();


        System.out.println("jsonObject = " + jsonObject);

        List<UserProductRecommend> list =userProductRecommendService.QueryAllUsProRec() ;
        UserProductRecommend userProductRecommend = new UserProductRecommend();


        UserSet.User usersetUser = new UserSet().new User();
        for (int i = 0; i < list.size(); i++) {
            userProductRecommend = list.get(i);
            userSet.put(userProductRecommend.getUsername())
                    .set(userProductRecommend.getProductName(), (int) userProductRecommend.getProfits()).create();
        }




        Recommend recommend = new Recommend();
        List<UserSet.Set> recommendations = recommend.recommend(jsonObject.getString("username"), userSet);
        System.out.println("jsonObject.username = " + jsonObject.getString("username"));
        System.out.println("-----------------------");
        for (UserSet.Set set : recommendations) {
            System.out.println(set.username+" "+set.score);
        }

        return "11";
    }

}
